﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace WenSkin.Controls
{
    [ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.All), DefaultEvent("ValueChanged")]
    [ToolboxBitmap(typeof(DateTimePicker))]
    public class ToolStripDateTimePicker : ToolStripControlHost
    {
        [Category("Wen"), Description("日期格式选择")]
        public DateTimePickerFormat Format { get => DateTimePicker.Format; set => DateTimePicker.Format = value; }
        [Category("Wen"), Description("自定义格式样式")]
        public string CustomFormat { get => DateTimePicker.CustomFormat; set => DateTimePicker.CustomFormat = value; }
       
        [Category("Wen"), Description("获取时间值")]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        [Bindable(true)]
        [RefreshProperties(RefreshProperties.All)]
        public DateTime Value { get => DateTimePicker.Value; set => DateTimePicker.Value = value; }
        public ToolStripDateTimePicker() : base(new DateTimePicker())
        {
            DateTimePicker.ValueChanged += MDateTimePicker_ValueChanged;
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public DateTimePicker DateTimePicker => base.Control as DateTimePicker;

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public override string Text
        {
            get { return string.Empty; }
            set { base.Text = string.Empty; }
        }

        public event EventHandler ValueChanged;

        private void MDateTimePicker_ValueChanged(object sender, EventArgs e)
        {
            ValueChanged?.Invoke(sender, e);
        }
    }
}
